<?php
  include_once('header.php');
  $id = $_GET['id'];
  $sql = "select * from user where id = '$id'";
  $result = mysqli_query($conn, $sql);
  if($result) {
    $row = mysqli_fetch_assoc($result);
  }

  // 权限选中
  function checkbox_limits($conn, $limits) {
    $id = $_GET['id'];
    $sql = "select * from user where id = $id and limits like'%".$limits."%'";
    $result = mysqli_query($conn, $sql);
    if(mysqli_num_rows($result) > 0) {
      echo 'checked';
    }
  }

  limits($conn, '权限管理');
?>
    <div class="layui-body" style="padding: 15px;">
    <!-- 权限管理 - 修改用户权限 -->
      <!-- 内容主体区域 -->
      <div>权限管理</div>
      <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
          <li><a class="layui-this">修改用户权限</a></li>
        </ul>
      </div>

      <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
          <div class="layui-row">
            <div class="layui-col-md8">
              <form class="layui-form" method="post" action="limits_update.php">
                <input type="hidden" name="id" value="<?php echo $id ?>" />
                <div class="layui-form-item">
                  <label class="layui-form-label">用户名 *</label>
                  <div class="layui-input-block">
                    <input type="text" name="username" required lay-verify="required" class="layui-input" value="<?php echo $row['username'] ?>"  disabled="disabled" />
                  </div>
                </div>

                <div class="layui-form-item">
                  <label class="layui-form-label">真实姓名</label>
                  <div class="layui-input-block">
                    <input type="text" name="real_name" class="layui-input" value="<?php echo $row['real_name'] ?>" disabled="disabled" />
                  </div>
                </div>

                <div class="layui-form-item">
                  <label class="layui-form-label">权限设置</label>
                  <div class="layui-input-block">
                    <input type="checkbox" name="limit0" value="图书管理" title="图书管理" <?php checkbox_limits($conn, '图书管理'); ?> />
                    <input type="checkbox" name="limit1" value="借阅管理" title="借阅管理" <?php checkbox_limits($conn, '借阅管理'); ?> />
                    <input type="checkbox" name="limit2" value="分类管理" title="分类管理" <?php checkbox_limits($conn, '分类管理'); ?> />
                    <input type="checkbox" name="limit3" value="位置管理" title="位置管理" <?php checkbox_limits($conn, '位置管理'); ?> />
                    <input type="checkbox" name="limit4" value="用户管理" title="用户管理" <?php checkbox_limits($conn, '用户管理'); ?> />
                    <input type="checkbox" name="limit5" value="权限管理" title="权限管理" <?php checkbox_limits($conn, '权限管理'); ?> />
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-input-block">
                    <input type="submit" class="layui-btn layui-btn-normal" value="提交" />
                  </div>
                </div>
              </form>
            </div>
          </div>
        </div>
      </div>

    </div>
<?php
  include('footer.php');
?>